package com.alexmaodali.mapper;

import com.alexmaodali.domain.dto.UserQueryDTO;
import com.alexmaodali.domain.po.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {
    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Select("select * from user where id=#{id} and status=1 and del=1")
    User getById(Integer id);

    /**
     * 查询全部
     *
     * @return
     */
    @Select("select * from user where status=1 and del=1")
    List<User> getAll();

    /**
     * 根据id删除
     *
     * @param id
     * @return
     */
    @Select("update user set del=0 where id=#{id}")
    void deleteById(Integer id);

    /**
     * 根据id禁用
     *
     * @param id
     * @return
     */
    @Select("update user set status=0 where id=#{id}")
    void disableById(Integer id);

    /**
     * 根据id启用
     *
     * @param id
     * @return
     */
    @Select("update user set status=1 where id=#{id}")
    void enableById(Integer id);

    /**
     * 插入用户
     *
     * @param user
     */
    @Insert("insert into user(account,age,diaphone,name,password,sex,status,del,create_time,update_time)" +
            " values(#{account},#{age},#{diaphone},#{name},#{password},#{sex},#{status},#{del},#{createTime},#{updateTime})")
    void insertUser(User user);

    /**
     * 更新用户
     *
     * @param user
     */
    @Update("update user set account=#{account},age=#{age},diaphone=#{diaphone},name=#{name}," +
            "password=#{password},sex=#{sex},status=#{status},del=#{del},update_time=#{updateTime} where id=#{id}")
    void updateUser(User user);

    /**
     * 分页查询
     *
     * @param userQueryDTO
     * @return
     */
    List<User> page(UserQueryDTO userQueryDTO);

    /**
     * 综合删除
     *
     * @param ids
     */
    void delete(List<Integer> ids);
}
